package com.he.consumer;

import com.he.constant.RabbitmqConstant;
import com.he.domain.dto.MailDTO;
import com.he.service.EmailService;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

/**
 * @author He
 * @version 1.0
 * @Date 2023/9/9 15:47
 * @Desc 邮件消费者
 */
@Service
public class EmailConsumer {

    @Resource
    private EmailService emailService;

    /**
     * 监听简单邮件队列
     * @param mail 邮件信息
     */
    @RabbitListener(queues = RabbitmqConstant.EMAIL_SIMPLE_QUEUE)
    public void listenSimpleEmailQueue(@Payload MailDTO mail) {
        System.out.println("------监听到了简单邮件队列------");
        emailService.sendSimpleMail(mail);
    }

    /**
     * 监听HTML邮件队列
     * @param mail 邮件信息
     */
    @RabbitListener(queues = RabbitmqConstant.EMAIL_HTML_QUEUE)
    public void listenHtmlEmailQueue(@Payload MailDTO mail) {
        System.out.println("------监听到了HTML邮件队列------");
        emailService.sendHtmlMail(mail);
    }

}
